home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************
- *
- * File: FinderEx.c
- * Version: 1.2
- * Author: David A. Lyons
- * Copyright: (c) 1991-92 by Apple Computer, Inc.
- *
- * Description: Skeleton Finder 6.0 Extension in MPW IIgs C
- *
- *----------------------------------------------------------
- *
- * Development History:
- *
- * 25-Jun-91 DAL
- *
- * Initial version.
- *
- * 17-Oct-91 DAL
- *
- * Updated for new interface files, and to make it a little more interesting.
- * (Happy Anniversary, Loma Prieta.)
- *
- * 24-Feb-92 DAL Version 1.1
- *
- * Our tellFinder SendRequest calls now have the stopAfterOne bit set (there is
- * only one Finder request procedure to receiv ethem, so it's slightly more
- * efficient to stop right away instead of making SendRequest look for
- * additional "Apple~Finder~..." procedures to send our request to).
- *
- * We now accept the srqGoAway code so we can be removed or replaced on the fly.
- * (If someone wants to remove us while the Finder is active, they should send
- * us a finderSaysGoodbye message first.)
- *
- * 25-Feb-92 DAL Version 1.2
- *
- * Cleaned up our handling of finderSaysGoodbye. Redundant requests should
- * do no harm (for example, we shouldn't call tellFinderRemoveFromExtras with
- * itemID zero).
- *
- ********************************************************************************/
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Memory.h>
- #include <IntMath.h>
- #include <Locator.h>
- #include <Window.h>
- #include <Menu.h>
- #include <Desk.h>
- #include <QDAux.h>
- #include <MiscTool.h>
-
- /* #include <GSOS.h> */
- /* #include <Font.h> */
- /* #include <Event.h> */
- /* #include <ProDOS.h> */
- /* #include <Control.h> */
- /* #include <List.h> */
- /* #include <Scrap.h> */
- /* #include <Dialog.h> */
- /* #include <StdFile.h> */
- /* #include <Print.h> */
- /* #include <LineEdit.h> */
- /* #include <Resources.h> */
-
- #include <Finder.h>
-
- int _toolErr; /* normally defined in Start.obj */
-
- char nameOfFinder[] = NAME_OF_FINDER; /* this avoids multiple copies of string */
-
- unsigned myItemID;
-
- pascal unsigned myRequestProc();
- unsigned handleHello(),
- handleGoodbye(),
- handleExtrasChosen(),
- handleGoAway();
- unsigned NumberOfIconsSelected();
-
- /* The following must be the function executed when this Init is run */
-
- void Installation()
- {
- int oldB = SaveDB();
-
- /* Check for System 6.0 -- QuickDraw version must be >=3.7 */
- if( (QDVersion() & 0x0FFF) < 0x0307)
- SysBeep();
- else
- {
- /* register our request procedure with the system */
- AcceptRequests("\pSampleCompanyName~SampleProductName~",
- MMStartUp(),
- myRequestProc);
- }
-
- RestoreDB(oldB);
- }
-
-
- /*
- Here's the extension's request procedure. The system calls this a lot, even
- reentrantly--so be careful not to mess up any global variables that are needed
- by other calls in progress.
-
- DO NOT USE LOTS OF STACK SPACE FOR REQUESTS YOU DO NOT ACCEPT! Some requests
- (like systemSaysBeep) can get sent while the stack is in page one, and if you
- use too much the system will crash.
-
- */
-
- pascal unsigned myRequestProc(request, dataIn, dataOut)
- unsigned request;
- long dataIn;
- long dataOut;
- {
- unsigned oldB = SaveDB();
- unsigned result = 0;
-
- switch(request)
- {
- case finderSaysHello:
- result = handleHello();
- break;
-
- case finderSaysGoodbye:
- result = handleGoodbye();
- break;
-
- case finderSaysExtrasChosen:
- result = handleExtrasChosen( (unsigned) dataIn );
- break;
-
- case srqGoAway:
- result = handleGoAway(dataOut);
- break;
- }
-
- RestoreDB(oldB);
- return( result ? 0x8000:0 );
- }
-
-
- unsigned handleHello()
- {
- tellFinderAddToExtrasOut myResultRecord;
-
- /*
- Menu item template--STATIC! This must stay in memory until we remove
- the item from the Extras menu.
- */
- static MenuItemTemplate myItemRecord = { 0x8000, 0, 0, 0, 0, 0,
- (Ref) "\pFinderEx menu item" };
-
- SendRequest(tellFinderAddToExtras,sendToName+stopAfterOne,nameOfFinder,
- &myItemRecord,&myResultRecord);
- myItemID = myResultRecord.menuItemID;
- return(0x8000);
- }
-
-
- unsigned handleGoodbye()
- {
- tellFinderRemoveFromExtrasOut myResultRecord;
-
- /*
- If the finderSaysGoodbye request is redundant, just accept it
- without doing anything.
- */
- if(!myItemID)
- return(0x8000);
-
- /* Remove our menu item */
- SendRequest(tellFinderRemoveFromExtras,sendToName+stopAfterOne,nameOfFinder,
- (long) myItemID, &myResultRecord);
- myItemID = 0;
- return(0x8000);
- }
-
-
- unsigned handleGoAway(dataOut)
- srqGoAwayOutPtr dataOut;
- {
-
- /*
- IMPORTANT -- Before accepting srqGoAway, disconnect your code
- from the system (remove run queue tasks, heartbeat tasks, notify
- procs, tool patches, interrupt handlers, etc. The caller will
- remove your request procedure (you can't safely remove a request
- procedure from inside that procedure). Then the caller will call
- UserShutDown on you.
-
- If you can't remove all your hooks from the system, you should
- accept srqGoAway but return resultID = $0000, telling the caller
- you cannot go away.
-
- For Finder Extensions, you may assume that the caller already
- sent you a finderSaysGoodbye message, if the Finder was active.
- */
-
- dataOut->resultID = MMStartUp(); /* yes, we can go away */
- dataOut->resultFlags = 0; /* let's not restart from memory */
- return(0x8000);
- }
-
-
- unsigned handleExtrasChosen(itemID)
- unsigned itemID;
- {
- char NumString[6];
- char *subArray[2];
- unsigned NumIcons;
-
- if(itemID != myItemID) return(0); /* not ours, so don't handle it */
-
- NumIcons = NumberOfIconsSelected();
-
- NumString[5] = '\0';
- Int2Dec(NumIcons, NumString, 5, 0);
- subArray[0] = NumString;
- while(*subArray[0]==' ') { subArray[0]++; }; /* skip leading blanks */
- subArray[1] = (NumIcons==1) ? "icon is" : "icons are";
-
- SysBeep2(sbOperationComplete+sbDefer);
- AlertWindow(awButtonLayout+awCString,subArray,
- "53/Yippety doo dah, it works! By the way, *0 *1 selected./^#6");
-
- return(0x8000);
- }
-
-
- typedef unsigned **WordHandle;
-
- unsigned NumberOfIconsSelected()
- {
- unsigned num;
- tellFinderGetSelectedIconsOut getIconsResult;
- SendRequest(tellFinderGetSelectedIcons,sendToName+stopAfterOne,nameOfFinder,
- 0L, &getIconsResult);
- num = **((WordHandle) getIconsResult.stringListHandle);
- DisposeHandle(getIconsResult.stringListHandle);
- return(num);
- }
-